package com.berchen.file;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;

public class PropertyTest {
    public static void main(String[] args) throws IOException {

        Properties properties=new Properties();
        properties.put("name","chenwh");
        properties.put("age","10");
        properties.put("phone","15208366072");

        FileWriter fileWriter=new FileWriter(PropertyTest.class.getClassLoader().getResource("").getPath()+ File.separator +"pro.properties");

        // store方法直接将数据写到文件中
        properties.store(fileWriter,"user info ");

        fileWriter.close();

        Properties read=new Properties();

        // 将文件读取加载到Properties对象中
        read.load(new FileReader(PropertyTest.class.getClassLoader().getResource("").getPath()+File.separator+"pro.properties"));

        System.out.println(read.get("name"));
    }
}
